//package cn.xspace.wnx.xmpp;
//
//
//import android.app.NotificationManager;
//import android.util.Log;
//
//import com.xspace.android.xafcommon.util.Constants;
//import com.xspace.android.xafcommon.util.DateUtils;
//import com.xspace.android.xafcommon.util.LogUtil;
//import com.xspace.android.xafcommon.util.XmlUtils;
//
//import org.jivesoftware.smack.Connection;
//import org.jivesoftware.smack.ConnectionConfiguration;
//import org.jivesoftware.smack.PacketListener;
//import org.jivesoftware.smack.Roster;
//import org.jivesoftware.smack.XMPPConnection;
//import org.jivesoftware.smack.filter.PacketFilter;
//import org.jivesoftware.smack.packet.IQ;
//import org.jivesoftware.smack.packet.Packet;
//import org.jivesoftware.smack.provider.PrivacyProvider;
//import org.jivesoftware.smack.provider.ProviderManager;
//import org.jivesoftware.smackx.GroupChatInvitation;
//import org.jivesoftware.smackx.OfflineMessageManager;
//import org.jivesoftware.smackx.PrivateDataManager;
//import org.jivesoftware.smackx.ServiceDiscoveryManager;
//import org.jivesoftware.smackx.bytestreams.socks5.provider.BytestreamsProvider;
//import org.jivesoftware.smackx.filetransfer.FileTransferManager;
//import org.jivesoftware.smackx.filetransfer.FileTransferNegotiator;
//import org.jivesoftware.smackx.packet.ChatStateExtension;
//import org.jivesoftware.smackx.packet.LastActivity;
//import org.jivesoftware.smackx.packet.OfflineMessageInfo;
//import org.jivesoftware.smackx.packet.OfflineMessageRequest;
//import org.jivesoftware.smackx.packet.SharedGroupsInfo;
//import org.jivesoftware.smackx.provider.AdHocCommandDataProvider;
//import org.jivesoftware.smackx.provider.DataFormProvider;
//import org.jivesoftware.smackx.provider.DelayInformationProvider;
//import org.jivesoftware.smackx.provider.DiscoverInfoProvider;
//import org.jivesoftware.smackx.provider.DiscoverItemsProvider;
//import org.jivesoftware.smackx.provider.MUCAdminProvider;
//import org.jivesoftware.smackx.provider.MUCOwnerProvider;
//import org.jivesoftware.smackx.provider.MUCUserProvider;
//import org.jivesoftware.smackx.provider.MessageEventProvider;
//import org.jivesoftware.smackx.provider.MultipleAddressesProvider;
//import org.jivesoftware.smackx.provider.RosterExchangeProvider;
//import org.jivesoftware.smackx.provider.StreamInitiationProvider;
//import org.jivesoftware.smackx.provider.VCardProvider;
//import org.jivesoftware.smackx.provider.XHTMLExtensionProvider;
//import org.jivesoftware.smackx.search.UserSearch;
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//import org.xmlpull.v1.XmlPullParser;
//import org.xmlpull.v1.XmlPullParserFactory;
//
//import java.io.ByteArrayInputStream;
//import java.io.InputStream;
//import java.io.UnsupportedEncodingException;
//import java.util.ArrayList;
//import java.util.List;
//
//import cn.xspace.chatui.bean.MessageEntity;
//import cn.xspace.library.util.ContentType;
//import cn.xspace.library.util.MsgType;
//import cn.xspace.library.util.XmppUtils;
//import cn.xspace.wnx.db.WNXDBManager;
//import cn.xspace.wnx.entity.Body;
//import cn.xspace.wnx.entity.PushBean;
//import cn.xspace.wnx.entity.WNXBean;
//import cn.xspace.wnx.entity.XmppBean;
//import cn.xspace.wnx.util.Notifier;
//import rx.Subscriber;
//
//
//public class XmppConnectionManager {
//
//    private static final String TAG = "XmppConnectionManager";
//    public static int SERVER_PORT = Constants.SERVER_INFO_PORT;// 端口
//    public static String SERVER_HOST = Constants.HOST_XMPP;// 服务器地址
//    private static ConnectionConfiguration connectionConfig;
//    public static String SERVER_NAME = "42.120.48.75";// 服务器名称
//    public static final String ACCOUNT_RESOURCE_KEY = "android";
//    private static int i = 0;
//    private static XMPPConnection connection;
//    private static FileTransferManager fileManager;
//    private static OfflineMessageManager offlineManager;
//    private static XmppConnectionManager xmppConnectionManager;
//
//    private NotificationManager manager;
//    private static ConnectionConfiguration connConfig;
//
//    public static synchronized XmppConnectionManager getInstance() {
//        if (xmppConnectionManager == null) {
//            xmppConnectionManager = new XmppConnectionManager();
//        }
//        return xmppConnectionManager;
//    }
//
//    // 静态加载ReconnectionManager ,重连后正常工作
//    static {
//        try {
//            Class.forName("org.jivesoftware.smack.ReconnectionManager");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    public boolean isConnected() {
//        if (connection == null) {
//            return false;
//        }
//        return connection.isAuthenticated();
//    }
//
//    /**
//     * 销毁xmpp连接.
//     *
//     * @author
//     * @update 2012-7-4 下午6:55:03
//     */
//    public void disconnect() {
//        LogUtil.d("wubaojie--->xmpp:disconnect");
//        if (connection != null) {
//            connection.disconnect();
//        }
//    }
//
//    public XMPPConnection init() {
//        Connection.DEBUG_ENABLED = false;
//        ProviderManager pm = ProviderManager.getInstance();
//        configure(pm);
//
//        connectionConfig = new ConnectionConfiguration(SERVER_HOST, SERVER_PORT, SERVER_NAME);
////       Connection.DEBUG_ENABLED = true;
//        connectionConfig.setSASLAuthenticationEnabled(false);// 不使用SASL验证，设置为false
//        connectionConfig.setSelfSignedCertificateEnabled(false);
//        connectionConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
//        // 允许自动连接
//        connectionConfig.setReconnectionAllowed(true);
//        // 允许登陆成功后更新在线状态
//        connectionConfig.setSendPresence(true);
//        // 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友
//        Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
//        connection = new XMPPConnection(connectionConfig);
//        connection.addPacketListener(packetListener, packetFilter);
//
//        return connection;
//    }
//
//    private void configure(ProviderManager pm) {
//        pm.addIQProvider("query", "jabber:iq:private",
//                new PrivateDataManager.PrivateDataIQProvider());
//        // Time
//        try {
//            pm.addIQProvider("query", "jabber:iq:time",
//                    Class.forName("org.jivesoftware.smackx.packet.Time"));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        // Roster Exchange
//        pm.addExtensionProvider("x", "jabber:x:roster",
//                new RosterExchangeProvider());
//        // Message Events
//        pm.addExtensionProvider("chat", "jabber:x:event",
//                new MessageEventProvider());
//        pm.addExtensionProvider("push", "jabber:x:event",
//                new MessageEventProvider());
//        // Chat State
//        pm.addExtensionProvider("active",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("composing",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("paused",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("inactive",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("gone",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        // XHTML
//        pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im",
//                new XHTMLExtensionProvider());
//        // Group Chat Invitations
//        pm.addExtensionProvider("x", "jabber:x:conference",
//                new GroupChatInvitation.Provider());
//        // Service Discovery # Items
//        pm.addIQProvider("query", "http://jabber.org/protocol/disco#items",
//                new DiscoverItemsProvider());
//        // Service Discovery # Info
//        pm.addIQProvider("query", "http://jabber.org/protocol/disco#info",
//                new DiscoverInfoProvider());
//        // Data Forms
//        pm.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
//        // MUC User
//        pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user",
//                new MUCUserProvider());
//        // MUC Admin
//        pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin",
//                new MUCAdminProvider());
//        // MUC Owner
//        pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner",
//                new MUCOwnerProvider());
//        // Delayed Delivery
//        pm.addExtensionProvider("x", "jabber:x:delay",
//                new DelayInformationProvider());
//        // Version
//        try {
//            pm.addIQProvider("query", "jabber:iq:version",
//                    Class.forName("org.jivesoftware.smackx.packet.Version"));
//        } catch (ClassNotFoundException e) {
//            // Not sure what's happening here.
//        }
//        // VCard
//        pm.addIQProvider("vCard", "vcard-temp", new VCardProvider());
//        // Offline Message Requests
//        pm.addIQProvider("offline", "http://jabber.org/protocol/offline",
//                new OfflineMessageRequest.Provider());
//        // Offline Message Indicator
//        pm.addExtensionProvider("offline",
//                "http://jabber.org/protocol/offline",
//                new OfflineMessageInfo.Provider());
//        // Last Activity
//        pm.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());
//        // User Search
//        pm.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
//        // SharedGroupsInfo
//        pm.addIQProvider("sharedgroup",
//                "http://www.jivesoftware.org/protocol/sharedgroup",
//                new SharedGroupsInfo.Provider());
//        // JEP-33: Extended Stanza Addressing
//        pm.addExtensionProvider("addresses",
//                "http://jabber.org/protocol/address",
//                new MultipleAddressesProvider());
//        pm.addIQProvider("si", "http://jabber.org/protocol/si",
//                new StreamInitiationProvider());
//        pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams",
//                new BytestreamsProvider());
//        pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
//        pm.addIQProvider("command", "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider());
//        pm.addExtensionProvider("malformed-action",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.MalformedActionError());
//        pm.addExtensionProvider("bad-locale",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.BadLocaleError());
//        pm.addExtensionProvider("bad-payload",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.BadPayloadError());
//        pm.addExtensionProvider("bad-sessionid",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.BadSessionIDError());
//        pm.addExtensionProvider("session-expired",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.SessionExpiredError());
//        LogUtil.e("解析完成");
//    }
//
//    static PacketListener packetListener = new PacketListener() {
//        @Override
//        public void processPacket(Packet packet) {
//
//            String xml = packet.toXML();
//            LogUtil.e(TAG, "wubaojie>>>" + "processPacket: " + xml);
//            try {
//                InputStream inputStream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
//
//                XmppBean mXmppBean = XmlUtils.toBean(XmppBean.class, inputStream);
//                if (mXmppBean == null) {
//                    return;
//                }
//
//                if (mXmppBean.properties != null && mXmppBean.properties.property != null) {
//                    //发送回执
//                    receipt(packet.getFrom(), mXmppBean.properties.property.value);
//                }
////                final PushBean model = parserXmlByPull(inputStream);
//
//                LogUtil.e(TAG, "wubaojie>>>" + "processPacket: model == " + (mXmppBean == null ? "null" : mXmppBean.toString
//                        ()));
//
//                if (XmppUtils.QAC_PLATFORM.equals(mXmppBean.msgInfo.platForm)) {
//                    //农技员推送
////                    Notifier.getInstance().sendNotificationQac(mXmppBean, true);
//
//                } else if (XmppUtils.WNX_PLATFORM.equals(mXmppBean.msgInfo.platForm)) {
//                    //微农信推送
//                    final MessageEntity messageEntity = new MessageEntity();
//                    final WNXBean wnxBean = new WNXBean();
//                    if (mXmppBean.msgInfo.bizCode.equalsIgnoreCase("02")) {
//                        messageEntity.msg_type = MsgType.WNX_MSG.toNumber();
//                        wnxBean.msg_type = MsgType.WNX_MSG.toNumber();
//                    } else if (mXmppBean.msgInfo.bizCode.equalsIgnoreCase("01")) {
//                        messageEntity.msg_type = MsgType.NOTICE.toNumber();
//                        wnxBean.msg_type = MsgType.NOTICE.toNumber();
//                    }
//                    wnxBean.msg_logo = mXmppBean.msgInfo.logo;
//                    messageEntity.msg_sender_id = mXmppBean.msgInfo.sendDeptId;
//                    wnxBean.msg_sender_id = mXmppBean.msgInfo.sendDeptId;
//                    messageEntity.msg_sender_name = mXmppBean.msgInfo.sendDeptName;
//                    wnxBean.msg_sender_name = mXmppBean.msgInfo.sendDeptName;
//
//                    messageEntity.msg_last_time = DateUtils.StringToString(null, mXmppBean.msgInfo.sendTime);
//                    wnxBean.msg_send_time = DateUtils.StringToString(null, mXmppBean.msgInfo.sendTime);
//                    messageEntity.msg_content_type = ContentType.TXT.toNumber();
//                    wnxBean.msg_content_type = ContentType.TXT.toNumber();
//
//                    JSONObject jsonObject = new JSONObject(mXmppBean.body);
//                    JSONArray newsArray = jsonObject.getJSONArray("newssnap");
//                    if (newsArray.length() > 0) {
//                        String firstTitle = newsArray.getJSONObject(0).optString("title");
//                        wnxBean.msg_title = firstTitle;
//                        messageEntity.msg_content = messageEntity.msg_sender_name + " ：" + firstTitle;
//                    } else {
//                        messageEntity.msg_content = messageEntity.msg_sender_name + " ：-----";
//                        wnxBean.msg_title = " -----";
//                    }
//                    wnxBean.msg_kind = mXmppBean.msgInfo.msgType;
//                    wnxBean.content = newsArray.toString();
//                    LogUtil.e(TAG, "wubaojie>>>" + "processPacket: wnxBean.msg_id : " + mXmppBean.msgInfo.msgId);
//                    String msg_id = mXmppBean.msgInfo.msgId;
//                    wnxBean.msg_id = msg_id;
//                    if (WNXDBManager.getInstance().isNoticeWnxExist(msg_id)) {
//                        LogUtil.e(TAG, "wubaojie>>>" + "processPacket: 已存在该条推送通知" + msg_id);
//                        return;
//                    }
//                    LogUtil.d(messageEntity.toString());
//                    LogUtil.d(wnxBean.toString());
//                    Notifier.getInstance().dealXmppNotice(messageEntity, wnxBean);
//                }
//
//
////                NoticeOrWNXDao.getInstance().getiNoticeData().insertWnxOrNotice(model)
////                        .subscribeOn(Schedulers.io())
////                        .observeOn(AndroidSchedulers.mainThread())
////                        .subscribe(new Action1<String>() {
////                            @Override
////                            public void call(String s) {
////                                Map inParam = new HashMap();
////                                inParam.put("type", "XmppConnectionManager");
////                                EventBus.getDefault().post(inParam);
////                            }
////                        });
//            } catch (UnsupportedEncodingException e) {
//                e.printStackTrace();
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    };
//
//    /**
//     * 发送消息回执的方法
//     *
//     * @param from
//     * @param value
//     */
//    private static void receipt(String from, String value) {
//        LogUtil.d(value);
//        String[] parms = value.split(",");
//        String squenceId = parms[2];
//        LogUtil.d(squenceId);
//        String phone = parms[1];
//        LogUtil.d(phone);
//        String platForm = parms[0];
//        LogUtil.d(platForm);
//        String pushUserId = parms[6];
//        LogUtil.d(pushUserId);
//        String receipTime = DateUtils.getCurrentDatetimeString(DateUtils.FORMAT_2);
//
//        MessageReceiptIQ iq = new MessageReceiptIQ();
//        // 消息id, 接收手机号码, 下发业务平台, 下发用户, 接收时间
//        // squeceId, mobile, from, name, sendtime
//        String parmsStr = squenceId + ","
//                + phone + "," + platForm
//                + "," + pushUserId + ","
//                + receipTime;
//        LogUtil.d(parmsStr);
//        iq.setParams(parmsStr);
//        iq.setTo(from);
//        iq.setType(IQ.Type.RESULT);
//        LogUtil.d("*************send MessageReceiptIQ==>" + iq.toXML() + "*************");
//        connection.sendPacket(iq);
//    }
//
//    static PacketFilter packetFilter = new PacketFilter() {
//
//        @Override
//        public boolean accept(Packet packet) {
//
////			com.cn.wt.wtutils.log.LogUtil.e("推送消息accept是1："+packet.toXML());
////			com.cn.wt.wtutils.log.LogUtil.e("推送消息accept是2："+packet.getFrom());
////			com.cn.wt.wtutils.log.LogUtil.e("推送消息accept是3："+packet.getPacketID());
////			com.cn.wt.wtutils.log.LogUtil.e("推送消息accept是4："+packet.getTo());
////			com.cn.wt.wtutils.log.LogUtil.e("推送消息accept是5："+packet.getXmlns());
////			//构建一个通知对象，指定了图标，标题，和时间
////			Notification notification = new Notification(R.drawable.ic_launcher, "通知", System.currentTimeMillis());
////			//TODO 处理消息
////			final org.jivesoftware.smack.packet.Message mes = (org.jivesoftware.smack.packet.Message) packet;
////			LogUtil.e("推送消息2222："+mes.toXML());
////			//界面跳转
////			Intent intent = new Intent(context, MainActivity.class);
////
////			//消息重复接收关键
////			intent.setData(Uri.parse("custom://" + System.currentTimeMillis()));
////			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
////			intent.putExtra("Body", mes.getBody());
////			intent.putExtra("From", mes.getFrom());
////			//触发界面跳转
////			PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent
//// .FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
////			//消息栏
////			notification.setLatestEventInfo(context, "您有新的消息", mes.getBody(), mPendingIntent);
////			notification.flags = Notification.FLAG_AUTO_CANCEL;//点击后自动消失
////			notification.defaults = Notification.DEFAULT_SOUND;//声音默认
//            //消息叠加
////			manager.notify(i, notification);
////			i++;
//            return true;
//        }
//    };
//
//    public static List<Body.NewssnapBean> toJson(String jsonStr) {
//        List<Body.NewssnapBean> dataList = new ArrayList<>();
//        try {
//            JSONObject json = new JSONObject(jsonStr);
//            JSONArray jsonArray = json.getJSONArray("newssnap");
//            int size = jsonArray.length();
//            for (int i = 0; i < size; i++) {
//                Body.NewssnapBean bean = new Body.NewssnapBean();
//                JSONObject jsonObject = jsonArray.getJSONObject(i);
//                bean.setImg(jsonObject.optString("img"));
//                bean.setSrc(jsonObject.optString("src"));
//                bean.setSummary(jsonObject.optString("summary"));
//                bean.setTitle(jsonObject.optString("title"));
//                dataList.add(bean);
//            }
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        return dataList;
//    }
//
//    private static PushBean parserXmlByPull(InputStream inputStream) throws Exception {
//        PushBean pushBean = null;
//        Body mBody = null;
//        PushBean.MsgInfo msgInfo = null;
//        List<PushBean.Property> propertys = null;
//
//        PushBean.Property property = null;
//        //    创建XmlPullParserFactory解析工厂
//        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
//        //    通过XmlPullParserFactory工厂类实例化一个XmlPullParser解析类
//        XmlPullParser parser = factory.newPullParser();
//        //    根据指定的编码来解析xml文档
//        parser.setInput(inputStream, "utf-8");
//
//        //    得到当前的事件类型
//        int eventType = parser.getEventType();
////        String id = null;
////        String to = null;
////        String type = null;
//        //    只要没有解析到xml的文档结束，就一直解析
//        while (eventType != XmlPullParser.END_DOCUMENT) {
//            switch (eventType) {
//                //    解析到文档开始的时候
//                case XmlPullParser.START_DOCUMENT:
//
//                    // XmlPullParser.
//                    break;
//                //    解析到xml标签的时候
//                case XmlPullParser.START_TAG:
//                    if ("message".equals(parser.getName())) {
//                        Log.d(TAG, " message ----begin");
//                        pushBean = new PushBean();
//                    } else if ("body".equals(parser.getName())) {
//                        mBody = new Body();
//                        Log.d(TAG, " body ----begin");
//                        String news = parser.nextText();
//                        List<Body.NewssnapBean> newList = toJson(news);
//                        Log.d(TAG, " body ----news  " + news);
//                        mBody.setNewssnap(newList);
//                        pushBean.body = mBody;
////                        body.setNewssnap(PushBean.Body.NewssnapBean.toJson(parser.nextText()));
////                        Log.d(TAG, " parser.nextText()1 >>" + parser.nextText());
////                        body = person.new Body();
////
//                        //    如果是name元素，则通过nextText()方法得到元素的值
//                        // person.setName(parser.nextText());
//                    } else if ("msgInfo".equals(parser.getName())) {
//                        Log.d(TAG, " msgInfo ----begin");
//                        msgInfo = pushBean.new MsgInfo();
//                    } else if ("platForm".equals(parser.getName())) {
//                        String name = parser.nextText();
//                        Log.d(TAG, " platForm ----begin" + name);
//                        msgInfo.setPlatForm(name);
//                    } else if ("bizCode".equals(parser.getName())) {
//                        String bizCode = parser.nextText();
//                        Log.d(TAG, " bizCode ----begin" + bizCode);
//                        msgInfo.setBizCode(bizCode);
//                    } else if ("logo".equals(parser.getName())) {
//                        String logo = parser.nextText();
//                        Log.d(TAG, " logo ----begin" + logo);
//                        msgInfo.setLogo(logo);
//                    } else if ("senderId".equals(parser.getName())) {
//                        String senderId = parser.nextText();
//                        Log.d(TAG, " senderId ----begin" + senderId);
//                        msgInfo.setSendDeptId(senderId);
//                    } else if ("senderName".equals(parser.getName())) {
//                        String senderName = parser.nextText();
//                        Log.d(TAG, " senderName ----begin" + senderName);
//                        msgInfo.setSenderName(senderName);
//                    } else if ("senderPhone".equals(parser.getName())) {
//                        String senderPhone = parser.nextText();
//                        Log.d(TAG, " senderPhone ----begin" + senderPhone);
//                        msgInfo.setSenderPhone(senderPhone);
//                    } else if ("sendTime".equals(parser.getName())) {
//                        String sendTime = parser.nextText();
//                        Log.d(TAG, " sendTime ----begin" + sendTime);
//                        msgInfo.setSendTime(sendTime);
//                    } else if ("sendDeptId".equals(parser.getName())) {
//                        String sendDeptId = parser.nextText();
//                        Log.d(TAG, " sendDeptId ----begin" + sendDeptId);
//                        msgInfo.setSendDeptId(sendDeptId);
//                    } else if ("sendDeptName".equals(parser.getName())) {
//                        String sendDeptName = parser.nextText();
//                        Log.d(TAG, " sendDeptName ----begin" + sendDeptName);
//                        msgInfo.setSendDeptName(sendDeptName);
//                    } else if ("msgId".equals(parser.getName())) {
//                        String msgId = parser.nextText();
//                        Log.d(TAG, " msgId ----begin" + msgId);
//
//                        msgInfo.setMsgId(msgId);
//                    } else if ("msgLogo".equals(parser.getName())) {
//                        String msgLogo = parser.nextText();
//                        Log.d(TAG, " msgLogo ----begin" + msgLogo);
//                        msgInfo.setMsgLogo(msgLogo);
//                    } else if ("msgSequenceId".equals(parser.getName())) {
//                        Log.d(TAG, " msgSequenceId ----begin");
//                        msgInfo.setMsgSequenceId(parser.nextText());
//                    } else if ("msgType".equals(parser.getName())) {
//                        String msgType = parser.nextText();
//                        Log.d(TAG, " msgType ----begin" + msgType);
//                        msgInfo.setMsgType(msgType);
//                    } else if ("msgChannel".equals(parser.getName())) {
//                        String msgChannel = parser.nextText();
//                        Log.d(TAG, " msgChannel ----begin" + msgChannel);
//                        msgInfo.setMsgChannel(msgChannel);
//                    } else if ("properties".equals(parser.getName())) {
//
//                        propertys = new ArrayList<>();
////                       properties=person.new properties();
//                    } else if ("property".equals(parser.getName())) {
//                        property = pushBean.new Property();
////                        property=person.new property();
//
//                    } else if ("name".equals(parser.getName())) {
//                        String name = parser.nextText();
//                        Log.d(TAG, " property name ----begin" + name);
//                        property.setName(name);
//                    } else if ("value".equals(parser.getName())) {
//                        String value = parser.nextText();
//                        Log.d(TAG, " value name ----begin" + value);
//                        property.setValue(value);
//                    }
//                    break;
//                //    解析到xml标签结束的时候
//                case XmlPullParser.END_TAG:
//                    if ("message".equals(parser.getName())) {
//                        Log.d(TAG, " message ----end");
//                        Log.d(TAG, " message ----end " + pushBean.body.getNewssnap().toString());
//                    } else if ("body".equals(parser.getName())) {
//                        Log.d(TAG, " body ----end");
//                        pushBean.body = mBody;
////                        body = null;
//                    } else if ("msgInfo".equals(parser.getName())) {
//                        Log.d(TAG, " msgInfo ----end");
//                        pushBean.msgInfo = msgInfo;
////                        msgInfo = null;
//                    } else if ("properties".equals(parser.getName())) {
//                        Log.d(TAG, " properties ----end");
//                        pushBean.properties = propertys;
//                    } else if ("property".equals(parser.getName())) {
//                        Log.d(TAG, " property ----end");
//                        propertys.add(property);
////                        property = null;
////                        propertyList.add(property);
////                        propertyList = null;
//                    }
//                    break;
//            }
//            //    通过next()方法触发下一个事件
//            eventType = parser.next();
//        }
//
////        for (int j = 0; j < beanList.size(); j++) {
////            cn.xspace.wnx.util.LogUtil.e("看看存的什么：" + beanList.get(j).toString());
////        }
//        return pushBean;
//    }
//
//    public XMPPConnection getConnection() {
//        if (connection == null || !connection.isConnected()) {
//            init();
//        }
//        return connection;
//    }
//
//    public static OfflineMessageManager getOffLineMessageManager() {
//        if (offlineManager == null) {
//            offlineManager = new OfflineMessageManager(connection);
//        }
//        return offlineManager;
//    }
//
//    public static FileTransferManager getFileTransferManager() {
//        if (fileManager == null) {
//            ServiceDiscoveryManager sdManager = ServiceDiscoveryManager
//                    .getInstanceFor(connection);
//            if (sdManager == null) {
//                sdManager = new ServiceDiscoveryManager(connection);
//            }
//            sdManager.addFeature("http://jabber.org/protocol/disco#info");
//            sdManager.addFeature("jabber:iq:privacy");
//            FileTransferNegotiator.setServiceEnabled(connection, true);
//            fileManager = new FileTransferManager(connection);
//        }
//        return fileManager;
//    }
//
//    public static void closeConnection() {
//        if (connection != null) {
//            connection.disconnect();
//            connection = null;
//        }
//    }
//
//    static Subscriber<String> wnxSub = new Subscriber<String>() {
//        @Override
//        public void onCompleted() {
//
//        }
//
//        @Override
//        public void onError(Throwable e) {
//
//        }
//
//        @Override
//        public void onNext(String s) {
//
//        }
//    };
//
//    static Subscriber<String> messageSub = new Subscriber<String>() {
//        @Override
//        public void onCompleted() {
//
//        }
//
//        @Override
//        public void onError(Throwable e) {
//            e.printStackTrace();
//        }
//
//        @Override
//        public void onNext(String s) {
//            LogUtil.d(s);
//        }
//    };
//
////    private static void addWNX(PushBean model, MessageEntity messageEntity, List<Body.NewssnapBean> newssnap) {
////        FileUtils.createDir(Environment.getExternalStorageDirectory() + "/test/");
////        DbUtils dbUtils = DbUtils.create(BaseAppliction.mInstance, Environment.getExternalStorageDirectory() +
////                "/test/testwnx.db", true);
////        try {
////            List<WNX> users = dbUtils.findAll(Selector.from(WNX.class));
////            WNX wnx = new WNX();
////            wnx.setMsgLogo(model.msgInfo.getMsgLogo());
////            wnx.setNum(i++);
////            wnx.setSendDeptId(model.msgInfo.getSendDeptId());
////            wnx.setSendDeptName(model.msgInfo.getSendDeptName());
////            wnx.setSummary(newssnap.get(0).getSummary());
////            wnx.setSendTime(model.msgInfo.getSendTime());
////            dbUtils.update(wnx, WhereBuilder.b("sendDeptId", "=", users.get(users.size() - 1).getSendDeptId()));
////        } catch (DbException e) {
////            e.printStackTrace();
////        }
////    }
//
//    private static void configureConnection() {
//        LogUtil.e("开始解析");
//        ProviderManager pm = ProviderManager.getInstance();
//        pm.addIQProvider("query", "jabber:iq:private",
//                new PrivateDataManager.PrivateDataIQProvider());
//        // Time
//        try {
//            pm.addIQProvider("query", "jabber:iq:time",
//                    Class.forName("org.jivesoftware.smackx.packet.Time"));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        // Roster Exchange
//        pm.addExtensionProvider("x", "jabber:x:roster",
//                new RosterExchangeProvider());
//        // Message Events
//        pm.addExtensionProvider("chat", "jabber:x:event",
//                new MessageEventProvider());
//        pm.addExtensionProvider("push", "jabber:x:event",
//                new MessageEventProvider());
//        // Chat State
//        pm.addExtensionProvider("active",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("composing",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("paused",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("inactive",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        pm.addExtensionProvider("gone",
//                "http://jabber.org/protocol/chatstates",
//                new ChatStateExtension.Provider());
//        // XHTML
//        pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im",
//                new XHTMLExtensionProvider());
//        // Group Chat Invitations
//        pm.addExtensionProvider("x", "jabber:x:conference",
//                new GroupChatInvitation.Provider());
//        // Service Discovery # Items
//        pm.addIQProvider("query", "http://jabber.org/protocol/disco#items",
//                new DiscoverItemsProvider());
//        // Service Discovery # Info
//        pm.addIQProvider("query", "http://jabber.org/protocol/disco#info",
//                new DiscoverInfoProvider());
//        // Data Forms
//        pm.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
//        // MUC User
//        pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user",
//                new MUCUserProvider());
//        // MUC Admin
//        pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin",
//                new MUCAdminProvider());
//        // MUC Owner
//        pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner",
//                new MUCOwnerProvider());
//        // Delayed Delivery
//        pm.addExtensionProvider("x", "jabber:x:delay",
//                new DelayInformationProvider());
//        // Version
//        try {
//            pm.addIQProvider("query", "jabber:iq:version",
//                    Class.forName("org.jivesoftware.smackx.packet.Version"));
//        } catch (ClassNotFoundException e) {
//            // Not sure what's happening here.
//        }
//        // VCard
//        pm.addIQProvider("vCard", "vcard-temp", new VCardProvider());
//        // Offline Message Requests
//        pm.addIQProvider("offline", "http://jabber.org/protocol/offline",
//                new OfflineMessageRequest.Provider());
//        // Offline Message Indicator
//        pm.addExtensionProvider("offline",
//                "http://jabber.org/protocol/offline",
//                new OfflineMessageInfo.Provider());
//        // Last Activity
//        pm.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());
//        // User Search
//        pm.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
//        // SharedGroupsInfo
//        pm.addIQProvider("sharedgroup",
//                "http://www.jivesoftware.org/protocol/sharedgroup",
//                new SharedGroupsInfo.Provider());
//        // JEP-33: Extended Stanza Addressing
//        pm.addExtensionProvider("addresses",
//                "http://jabber.org/protocol/address",
//                new MultipleAddressesProvider());
//        pm.addIQProvider("si", "http://jabber.org/protocol/si",
//                new StreamInitiationProvider());
//        pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams",
//                new BytestreamsProvider());
//        pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
//        pm.addIQProvider("command", "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider());
//        pm.addExtensionProvider("malformed-action",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.MalformedActionError());
//        pm.addExtensionProvider("bad-locale",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.BadLocaleError());
//        pm.addExtensionProvider("bad-payload",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.BadPayloadError());
//        pm.addExtensionProvider("bad-sessionid",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.BadSessionIDError());
//        pm.addExtensionProvider("session-expired",
//                "http://jabber.org/protocol/commands",
//                new AdHocCommandDataProvider.SessionExpiredError());
//        LogUtil.e("解析完成");
//    }
//}
